import {Component, OnInit} from '@angular/core';
import {Page} from '../../../public/util/page';
import {SettingUrl} from '../../../public/setting/setting_url';
import {Enums, OreAccountState} from '../../../public/setting/enums';
import {UserService} from '../user.service';
import {MainService} from '../../../public/service/main.service';

@Component({
  selector: 'app-user-ore',
  templateUrl: './user-ore.component.html',
  styleUrls: ['./user-ore.component.css']
})
export class UserOreComponent implements OnInit {
  public searchParams: any = {};//搜索参数
  public oreRecordList: Page = new Page(); //供应商
  public _loading: boolean = false;
  public routerLinks = SettingUrl.ROUTERLINK;//路由
  public states = Enums.userOreState;       // 状态
  public oreAccountState = OreAccountState;
  public oreStates: Array<any> = [];

  constructor(private userService: UserService, private mainService: MainService) {
    this.oreStates = this.mainService.getEnumDataList(Enums.userOreState);
    this.oreStates.unshift({key: '', val: '全部'});
  }

  ngOnInit() {
    this.queryOreRecordList();
  }

  /**
   * 查询oreRecord列表
   * @param curPage 当前页
   */
  queryOreRecordList(curPage?: number) {
    this._loading = true;
    if (curPage) this.oreRecordList.curPage = curPage;//当有页码时，查询该页数据
    this.oreRecordList.params = {
      state: this.searchParams.state, //state
      account: this.searchParams.account, //account
      curPage: this.oreRecordList.curPage, //目标页码
      pageSize: this.oreRecordList.pageSize, //每页条数
    };
    this.userService.getUserOreList(this.oreRecordList.params).then((res: Page) => {
      this._loading = false;
      this.oreRecordList = res;
    }).catch(err => {
      this._loading = false;
    });
  }

  /**
   * 重置搜索
   */
  resetSearch() {
    this.searchParams = {};
    this.queryOreRecordList(1);
  }
}
